home *** CD-ROM | disk | FTP | other *** search
- /*
- File: mylistdef.c
-
- Contains: This LDEF displays small icons to the left of text in a list.
- The small icon is stored in the first 16 bytes of each cell.
-
- Written by: Steven Falkenburg
-
- Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 8/10/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
- #include <Types.h>
- #include <QuickDraw.h>
- #include <Lists.h>
- #include <Memory.h>
-
- /* constants for spacing */
-
- #define kLeftOffset 2
- #define kTopOffset 0
- #define kIconSpace 2
-
- /* prototypes */
-
- void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort);
- pascal void theLDEF(short lMessage,Boolean lSelect,Rect *lRect,Cell lCell,
- short lDataOffset,short lDataLen,ListHandle lHandle);
- /* main LDEF entry point */
-
- pascal void theLDEF(short lMessage,Boolean lSelect,Rect *lRect,Cell lCell,
- short lDataOffset,short lDataLen,ListHandle lHandle)
- {
- #pragma unused(lCell)
- FontInfo fontInfo; /* font information (ascent/descent/etc) */
- ListPtr listPtr; /* pointer to store dereferenced list */
- SignedByte hStateList,hStateCells; /* state variables for HGetState/SetState */
- Ptr cellData; /* points to start of cell data for list */
- Ptr theSICN; /* points to SICN to be drawn */
- short leftDraw,topDraw; /* left/top offsets from topleft of cell */
-
- /* lock and dereference list mgr handles */
-
- hStateList = HGetState((Handle)lHandle);
- HLock((Handle)lHandle);
- listPtr = *lHandle;
- hStateCells = HGetState(listPtr->cells);
- HLock(listPtr->cells);
- cellData = *(listPtr->cells);
-
- switch (lMessage) {
- case lInitMsg:
- /* we don't need any initialization */
- break;
-
- case lDrawMsg:
- EraseRect(lRect);
-
- if (lDataLen > 0) {
-
- /* determine starting point for drawing */
-
- leftDraw = lRect->left+listPtr->indent.h+kLeftOffset;
- topDraw = lRect->top+listPtr->indent.v+kTopOffset;
-
- /* plot SICN (first 32 bytes) */
-
- if (lDataLen > 32) {
- theSICN = cellData+lDataOffset;
- DrawSICN(theSICN,leftDraw,topDraw,listPtr->port);
- lDataOffset += 32;
- lDataLen -= 32;
- }
- leftDraw += 16+kIconSpace;
-
- /* plot text (offset 32 bytes onward) */
-
- GetFontInfo(&fontInfo);
- MoveTo(leftDraw,topDraw+fontInfo.ascent);
-
- /* set condensed mode if necessary (if the text doesn't fit otherwise) */
-
- TextFace(0);
- if (TextWidth(cellData,lDataOffset,lDataLen) > (lRect->right - leftDraw))
- TextFace(condense);
-
- DrawText(cellData,lDataOffset,lDataLen);
- }
-
- if (!lSelect)
- break;
-
- case lHiliteMsg:
- InvertRect(lRect);
- break;
-
- case lCloseMsg:
- break;
- }
-
- HSetState((Handle)listPtr->cells,hStateCells);
- HSetState((Handle)lHandle,hStateList);
- }
-
-
- /* this procedure draws a small icon using CopyBits */
-
- void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort)
- {
- BitMap iconMap;
- Rect destRect;
-
- iconMap.baseAddr = theSICN;
- iconMap.rowBytes = 2;
- SetRect(&iconMap.bounds,0,0,16,16);
- SetRect(&destRect,0,0,16,16);
- OffsetRect(&destRect,left,top);
- CopyBits(&iconMap,&drawPort->portBits,&iconMap.bounds,&destRect,
- srcCopy,nil);
- }
-